|
|
 |
|
|
|
|
:
' Get the pixels from pic_from. GetBitmapPixels pic_from, input_pixels, bits_per_pixel
' Get the pixels from pic_to. GetBitmapPixels pic_to, result_pixels, bits_per_pixel
' Calculate the output pixel values. For iy_out = 0 To pic_to.ScaleHeight - 1
For ix_out = 0 To pic_to.ScaleWidth - 1 ' Map the pixel value from
' (ix_out, iy_out) to (x_in, y_in). MapPixel ix_out, iy_out, x_in, y_in
' Interpolate to find the pixel's value.
: Next ix_out
Next iy_out
' Set pic_to's pixels. SetBitmapPixels pic_to, bits_per_pixel, result_pixels
pic_to.Picture = pic_to.Image
End Sub |
|
|
|
|
|
|
|
|
All the information about the particular transformation (rotation, scaling, stretching, etc.) is contained in the MapPixel subroutine. That makes TransformImage very general. You can modify MapPixel to implement a different mapping function without changing the rest of the program. |
|
|
|
|
|
|
|
|
Although program Trans uses an approach that is very easy to modify, in practice, it imposes some overhead. The program calls subroutine MapPixel for every pixel in the image. With a 100-by-100 pixel output image, for instance, the program calls MapPixel 10,000 times. All those function calls slow the program slightly. You can make the program less general but faster if you move the pixel mapping function directly into subroutine TransformImage. |
|
|
|
|
|
|
|
|
Program Trans lets you compare these approaches. Use the Transform button to make the program rotate an image using subroutine TransformImage. Use the Rotate button to make the program rotate the image with the pixel mapping directly inside the transformation routine. In one set of tests on a 133MHz Pentium processor, rotating the image took roughly 10 percent longer when the more general TransformImage subroutine was used. |
|
|
|
|
|
|
|
|
Most of the example programs described in this chapter use the more general technique because it is easier to understand and modify. You can make the programs slightly faster if you bring the pixel mapping functions inside the TransformImage subroutine. |
|
|
|
|
|